package com.example.myfinalhomework;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.myfinalhomework.Main;
import com.example.myfinalhomework.R;
import com.example.myfinalhomework.xijies;
import com.example.myfinalhomework.userrelated;

import java.util.List;

public class Adapter extends ArrayAdapter<userrelated> {
    List<userrelated> items;
    public Adapter(Context context, List<userrelated> items) {
        super(context, R.layout.show,items);
        this.items=items;
    }
    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(getContext());
            convertView = inflater.inflate(R.layout.show, parent, false);
        }

        ImageView img = convertView.findViewById(R.id.img);
        TextView name = convertView.findViewById(R.id.name);
        userrelated dd = items.get(position);
        name.setText(dd.getName());
        View finalConvertView = convertView;
        finalConvertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), xijies.class);
                intent.putExtra("name", dd.getName());
                getContext().startActivity(intent);
            }
        });

        return convertView;
    }
}
